package pt.iscte.pcd.horserace;

import java.awt.Color;

import javax.swing.JTextField;

public class Horse extends Thread {
	private static final double MAX_SLEEP = 100;
	private JTextField track;
	private Horse[] horses;

	public Horse(JTextField track, Horse[] horses) {
		super();
		this.track = track;
		this.horses = horses;
	}

	@Override
	public void run() {
		try {
			for (int i = Race.MAX_STEPS; i >= 0; i--) {
				track.setText(i + "");
				sleep((int) (Math.random() * MAX_SLEEP));
			}
			track.setBackground(Color.GREEN);
			for(Horse horse: horses){
				horse.interrupt();
			}
		} catch (InterruptedException e) {
			
		}

	}
}
